package com.Clause;

import com.Modele;

public class Predicat extends ClauseElement{

	private String nom;
	private Variable[] variables;

	public Predicat(String nom){
		this.nom=nom;
		variables = new Variable[5];
	}

	public Predicat(String nom, Variable ... variables){
		this.nom = nom;
		this.variables = variables;
	}

	public Predicat(Modele modele){
		this.nom = modele.getPredicat();
		variables = new Variable[modele.getArite()];
	}
	
	public void setVariable(int index,Variable var){
		if(index < variables.length)
			variables[index] = var;
	}

	public Variable[] getVariable(){
		return variables;
	}

	public String getNom(){
		return nom;
	}

	public String toString(){
		StringBuffer sb = new StringBuffer();
		sb.append(nom).append("(");
		for(int i=0;i<variables.length;++i){
			sb.append(variables[i]);
			if(i<variables.length-1)
				sb.append(",");
		}
		sb.append(")");
		return sb.toString();
	}
	
	public Predicat copie(){
		Predicat p = new Predicat(new String(nom));
		p.variables = new Variable[variables.length];
		for(int i=0;i<variables.length;++i){
			p.variables[i] = variables[i].copie();
		}
		return p;
	}

}
